#pragma once

#include <qlabel.h>
#include <qcolor.h>
#include <qcolordialog.h>
#include <OgreColourValue.h>

#ifndef COLOR__CHOOSER__INCLUDED__HH
#define COLOR__CHOOSER__INCLUDED__HH

class ColorChooser : public QLabel
{
	Q_OBJECT
	QColor mColor;
signals:
	void colorChanged( const QColor& c );

public:
	ColorChooser( QWidget * parent, const QColor& defCol = Qt::black ) : QLabel( parent )
	{
		setColor( defCol );
		setMinimumSize( 25, 20 );
	}
	ColorChooser( QWidget * parent, const Ogre::ColourValue& defCol ) : QLabel( parent )
	{
		setColor( defCol );
		setMinimumSize( 25, 20 );
	}
	void mouseReleaseEvent(QMouseEvent *e)
	{
		QLabel::mouseReleaseEvent( e );
		mColor = QColorDialog::getColor( mColor, parentWidget(), "Choose Color", QColorDialog::ShowAlphaChannel );
		setColor( mColor );
		emit colorChanged( mColor );
	}
	const QColor& color() const{ return mColor; }
	Ogre::ColourValue ogreColor() const{ return Ogre::ColourValue( mColor.redF(), mColor.greenF(), mColor.blueF(), mColor.alphaF() ); }
	
	void setColor( float r, float g, float b, float a = 1.0f ){	setColor( QColor::fromRgbF( r, g, b, a ) ); }
	void setColor( const Ogre::ColourValue& col ){	setColor( QColor::fromRgbF( col.r, col.g, col.b, col.a ) ); }
	void setColor( const QColor & col )
	{
		mColor = col;
		QString border = "border-width: 2px; border-color: black; border-style: solid;";
		setStyleSheet( "background-color: rgb("+QString::number(col.red())+","+QString::number(col.green())+","+QString::number(col.blue())+","+QString::number(col.alpha())+");"+border );
	}
};

#endif